{% if profile.name %}
{% set title = "Perfil de " + profile.name %}
{% else %}
{% set title = "Perfil de " + profile.username %}
{% endif %}

{% extends 'layouts/layout.html' %}
{% block opengraph %}
<meta name="description" content='Libreflix é uma plataforma de streaming aberta e colaborativa que reúne produções audiovisuais independentes, de livre exibição e que fazem pensar.'>
<meta name="keywords"  content="libreflix, {{profile.name}} Libreflix, liberflix, librefix" />

<meta property="og:image" content="
{%- if profile.twitter %}{{ profile.gravatar }}{%- elseif profile.picture %}{{ profile.picture }}{%- else %}{{ profile.gravatar }}{%- endif %}"/>

<meta property="og:type" content="website" />
<meta property="og:url" content="https://libreflix.org/u/{{ profile.username }}" />
<meta property="og:title" content="{{profile.name}} - Libreflix" />
<meta property="og:description" content="Perfil de {{profile.name}} no Libreflix é uma plataforma de streaming aberta e colaborativa que reúne produções audiovisuais independentes, de livre exibição e que fazem pensar." />
<meta property="og:site_name" content="Libreflix" />

<!-- twitter metatags-->
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="{{profile.name}} - Libreflix">
<meta name="twitter:description" content="Perfil de {{profile.name}} no Libreflix é uma plataforma de streaming aberta e colaborativa que reúne produções audiovisuais independentes, de livre exibição e que fazem pensar.">
<meta name="twitter:image" content="{% if profile.twitter %}{{ profile.gravatar }}{% elseif profile.picture %}{{ profile.picture }}{% else %}{{ profile.gravatar }}{% endif %}">
{% endblock %}

{% block body %}
<div class="container-fluid">
  {% if messages.success %}
  <div role="alert" class="alert alert-success">
    {% for success in messages.success %}
    <div>{{ success.msg }}</div>
    {% endfor %}
  </div>
  {% endif %}
  {% if messages.error %}
  <div role="alert" class="alert alert-danger">
    {% for error in messages.error %}
    <div>{{ error.msg }}</div>
    {% endfor %}
  </div>
  {% endif %}
  {% if messages.info %}
  <div role="alert" class="alert alert-info">
    {% for info in messages.info %}
    <div>{{ info.msg }}</div>
    {% endfor %}
  </div>
  {% endif %}

</div>


{% macro printWatch(w, loop) -%}

    {% if w.featured == 'true' or w.featured %}

    <li class="col-md-3">
      <a role="button" data-toggle="modal" style="border-bottom: 0px solid;"  data-toggle="modal" data-target="#assistir{{ loop.index }}">
      <div class="cover">
          <img src="{%- if w.thumb480 %}{{ w.thumb480 }}?resize=480,270&crop=entropy {%- elseif w.imgbg %} {{ w.imgbg }}?resize=480,270&crop=entropy{%- endif %}" title="{{ w.title }}{%- if w.subtitle %} - {{ w.subtitle }}{%- endif %} ({{ w.year }})" class="fadeCatalogo" onload="this.style.opacity='1'"/>
        <div class="cover_wrap">
          <div class="cover_info">
            <h3>{{ w.title | truncate(45) }}</h3>
            <h4>
              {{ w.subtitle | truncate(35) }}
              {% if w.subtitle %} </h4> <h4> {%endif%} {{w.year}}
              {% if w.classind  %} &middot; <span class="classind">{{ w.classind }}</span>{% endif %}
              {% if w.duration  %} &middot; <i class="fa fa-clock-o" aria-hidden="true"></i> {{ w.duration }} {% endif %}
            </h4>
          </div>
        </div>
        <!--<h3>{{ w.title }}</h3>-->
      </div>
      </a>

    </li>
    <div class="modal" id="assistir{{ loop.index }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel{{ loop.index }}">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times-circle exitTimes"></i></button>
            <a href="/i/{{ w.permalink }}"><button type="button" class="splash-play"><img src="/img/play.png" alt="Play"></button></a>
            <!-- <h4 class="modal-title" id="myModalLabel{{ loop.index }}">{{ w.title }} {% if w.subtitle %} - {{ w.subtitle }} {% else %} {% endif %}</h4> -->
            <a href="/i/{{ w.permalink }}"><div class="splash" style="background-image: url('{{ w.imgbg }}');">
            </div></a>
          </div>
          <div class="modal-body">
            <h2> {{ w.title }}</h2>

            <h4>
              {{ w.subtitle }}
              {% if w.subtitle %} &middot; {%endif%} {{w.year}}
              {% if w.classind  %} &middot; <span class="classind">{{ w.classind }}</span>{% endif %}
              {% if w.duration  %} &middot; <i class="fa fa-clock-o" aria-hidden="true"></i> {{ w.duration }} {% endif %}
            </h4>
            <div class="sinopse">{{ w.sinopse | truncate(300)}}</div>
            <h4> Tags: {% set list1 = w.tags.split(',') %}{% for list in list1 %}{% if loop.index0 < 6 %}<a href="/t/{{ list | trim}}"><span class="label label-default">{{ list | trim}}</span></a>{% endif %}{%if (loop.index0 < loop.length-1) or (loop.index0 < 6) %} {%endif%}{% endfor %}</h4>
          </div>
          <div class="modal-footer">
            {% if user.mod or user.adm %}<a href="/edit/{{ w._id }}"><button type="button" class="btn btn-danger"><i class="fa fa-edit"></i> t('Editar') </button></a>{% endif %}
            <button type="button" class="btn btn-default" data-dismiss="modal"> <i class="fa fa-times-circle"></i> {{ t('Fechar') }} </button>
            <a href="/i/{{ w.permalink }}"><button type="button" class="btn btn-success"> <i class="fa fa-info-circle"></i> {{ t('Informações') }} </button></a>
            <!-- <a href="/i/{{ w.permalink }}"><button type="button" class="btn btn-success">{{ t('Assistir') }} <i class="fa fa-play-circle"></i></button></a> -->
          </div>
        </div>
      </div>
    </div>
    {% endif %}


{%- endmacro %}

<section class="work">
  <div class="profile_banner" style="background: url({{ profile.cover_picture}}) no-repeat center center;">
  </div>
  <div class="profile_banner_content">
    <img src="{%- if profile.twitter -%}
                {{ profile.gravatar }}
              {%- elseif profile.picture -%}
                {{ profile.picture }}
              {%- else -%}
                {{ profile.gravatar}}
              {%- endif -%}"
    alt="{{ profile.username }}" class="profile_pic">
    <h2>{% if profile.name %} {{ profile.name }} {% else %} {{ profile.username }} {% endif %}</h2>
    <h4>
      {% if profile.name %} @{{ profile.username }}  {% else %} {% endif %}
      {% if profile.location %} · {{ profile.location }} {% endif %}
      {% if profile.website %} · <a href="http://{{ profile.website | replace("https://", "") | replace("http://", "")}}">{{ profile.website | replace("https://", "") | replace("http://", "")}}</a>  {% endif %}
    </h4>
  </div>


  <!-- Longas Que o User cadastrou -->

  <h3>{{t('Obras Favoritas')}}</h3>
  <section class="work">
  <div class="grid">
    <ul class="entries">
      {% for i in interactions %}
        {% if i.favorite %}
        {{ printWatch(i.attachedToWatch, loop) }}
        {% endif %}
      {% endfor %}
    </ul>
  </div>
  </section>

  <h3>{{t('Obras Assistidas')}}</h3>
  <section class="work">
  <div class="grid">
    <ul class="entries">
      {% for i in interactions %}
        {% if i.alreadyWatched %}
        {{ printWatch(i.attachedToWatch, loop) }}
        {% endif %}
      {% endfor %}
    </ul>
  </div>
  </section>

</section>


{% endblock %}
